package org.thread.test02.demo04;

/**
 * 守护线程
 *
 * @author CSY
 * @date 2025 - 03 - 07
 */
public class GuardThread extends Thread {
    private FileData fileData;

    public GuardThread() {
    }

    public GuardThread(FileData fileData) {
        this.fileData = fileData;
    }

    @Override
    public void run() {
        while (true) {

            if(fileData.getTotalSize() == 0){
                continue;
            }
            double percent = fileData.getCopiedSize() * 1.0   / fileData.getTotalSize() * 100;
            System.out.printf("当前进度：%.2f %% %n",percent);
            try {
                Thread.sleep(5);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }

    }
}
